//
//  DetaillCell.m
//  植物管理
//
//  Created by liujianlong on 2022/11/23.
//

#import "DetaillCell.h"
#import "ImgCell.h"

@interface DetaillCell()
@property (strong, nonatomic) IBOutlet UICollectionView *collectionView;
@property (strong, nonatomic) IBOutlet UILabel *namt;
@property (strong, nonatomic) IBOutlet UILabel *num;
@property (strong, nonatomic) IBOutlet UILabel *job;
@property (strong, nonatomic) IBOutlet UILabel *date;
@property (strong, nonatomic) IBOutlet UILabel *detail;

@end
@implementation DetaillCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self.collectionView registerNib:[ImgCell nib] forCellWithReuseIdentifier:[ImgCell ID]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}
- (void)setModel:(Job *)model{
    _model = model;
    self.namt.text = [NSString stringWithFormat:LS(@"名称:%@"),model.plant];
    self.num.text = [NSString stringWithFormat:LS(@"数量:%@颗"),model.num];
    self.job.text = [NSString stringWithFormat:LS(@"记农事:%@, %@"),LS(model.job),model.times];
    self.date.text = [NSString stringWithFormat:LS(@"种植时间:%@"),[NSDate transToDate:@"yyyy-MM-dd" :model.stamp]];
    self.detail.text = LS(model.plantDetail);
    [self.collectionView reloadData];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.model.imgs.count;
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ImgCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:[ImgCell ID] forIndexPath:indexPath];
    cell.img.image = [UIImage imageWithData:self.model.imgs[indexPath.row]];
    cell.deleteBtn.hidden = YES;
    CGFloat w = (SCREEN_WIDTH - 40);
    CGSize size = CGSizeMake(w, 330.0/220*w);
    cell.bounds = CGRectMake(0, 0, size.width, size.height);
    return  cell;
}

#pragma mark - UICollectionViewDelegate
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
}

#pragma mark - UICollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat w = (SCREEN_WIDTH - 40);
    return  CGSizeMake(w, 330.0/220*w);
}
- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return  UIEdgeInsetsMake(20, 20, 20, 20);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    return 20;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    return 10;
}
@end
